'''
    module_of_msg.py
    author: yizimi-yuanxin
    update: 23.3.15
'''

from data_type_yizimi import *

def get_string_mode():
    '''
    创建string类型的模式，仅适用于data
    '''
    string_mode = msg_mode(0x00000000, "string")
    string_mode.add_mode_seg(0, "data")
    return string_mode

def get_pcapheader_mode():
    '''
    创建pcap header的格式，用于读取pcap文件
    '''
    Pcapheader_mode = msg_mode(0xFFFFFFFF, "Pcapheader")
    Pcapheader_mode.add_mode_seg(4, 'Magic')
    Pcapheader_mode.add_mode_seg(2, 'Major')
    Pcapheader_mode.add_mode_seg(2, 'Minor')
    Pcapheader_mode.add_mode_seg(4, 'ThisZone')
    Pcapheader_mode.add_mode_seg(4, 'SigFigs')
    Pcapheader_mode.add_mode_seg(4, 'SnapLen')
    Pcapheader_mode.add_mode_seg(4, 'LinkType')
    Pcapheader_mode.set_data_mode(-1)
    return Pcapheader_mode

def get_packetheader_mode():
    '''
    创建packet header的格式，用于pcap文件分隔报文和确定报文长度
    '''
    Packetheader_mode = msg_mode(0xFFFFFFFE, "Packetheader")
    Packetheader_mode.add_mode_seg(4, "ts_sec")
    Packetheader_mode.add_mode_seg(4, "ts_usec")
    Packetheader_mode.add_mode_seg(4, "incl_len")
    Packetheader_mode.add_mode_seg(4, "orig_len")
    Packetheader_mode.add_mode_seg(-1, "data")
    Packetheader_mode.set_datalen_name("incl_len")
    Packetheader_mode.set_data_mode(-1)
    return Packetheader_mode

def get_Ethernet_II_mode():
    '''
    
    '''
    Ethernet_II_mode = msg_mode(0x00000001, "Ethernet_II")
    Ethernet_II_mode.add_mode_seg(6, "dMAC")
    Ethernet_II_mode.add_mode_seg(6, "sMAC")
    Ethernet_II_mode.add_mode_seg(2, "Type")
    Ethernet_II_mode.add_mode_seg(-1, "data")
    Ethernet_II_mode.set_datalen_name(None)
    Ethernet_II_mode.set_data_mode(-1)
    return Ethernet_II_mode



str_mode = get_string_mode()
EthII_mode = get_Ethernet_II_mode()
Pcaph_mode = get_pcapheader_mode()
Pkt_mode = get_packetheader_mode()